using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RespawnPoint : MonoBehaviour
{
    public bool _isAvailable;
    private bool _isCapturing;
    private float _timer;
    private float _duration;

    private void FixedUpdate()
    {
        if (_isCapturing)
        {
            _timer++;
        }
    }

    public void OnCollisionEnter(Collision collision)
    {
        Player player = collision.gameObject.GetComponent<Player>();
        _isCapturing = player != null && player._isTeamEscort;
    }

    public void OnCollisionStay(Collision collision)//stay for a while to make the respawn point available
    {
        Player player = collision.gameObject.GetComponent<Player>();
        if (player != null && player._isTeamEscort)
        {
            _isAvailable = _timer >= _duration;
        }
    }

    public void OnCollisionExit(Collision collision)
    {
        Player player = collision.gameObject.GetComponent<Player>();
        _isCapturing = player != null && !player._isTeamEscort;
    }
}